<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cn.vuejs.org/js/vue.js"></script>
    <link rel="stylesheet" href="/static/css/want_buy.css">
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <link rel="stylesheet" href="../static/layui/css/layui.css">
    <script src="../static/layui/layui.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="want_buy">
    <span th:text="${session.user.getUser_id()}" hidden="hidden" id="user_id_span"></span>
    <div class="goodsListBox" v-for="item in List">
<!--        <span   id="order_id">{{item.user_id}}</span>-->
        <div class="left_div">
            <img id="goods_picture" :src="item.goods_picture" alt="">
        </div>
       <div class="right_div">
           <div class="goods_describe">
               <span>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;{{item.goods_describe}}</span>
           </div>
           <div class="price_btn">
               <div class="goods_price">
                   <div style="margin-top: 11px">
                       <span style="font-size: 25px;color: red">￥{{item.goods_price}}</span>
                   </div>
               </div>
               <div class="btn_box">
                   <button class="layui-btn layui-btn-sm" @click="buy_now(item.user_id)">现在付款</button>
                   <button class="layui-btn layui-btn-primary layui-btn-sm" title="点击按钮将宝贝从购物清单中删除" @click="deleteFromShoppingCart(item.goods_id)" style="color: rgb(255,2,2);font-size: 13px">考虑一下</button>
               </div>
           </div>
       </div>
    </div>

</div>
</body>
<script>
    var user_id=document.getElementById("user_id_span").innerText;
    // var order_id=document.getElementById("order_id").innerHTML;
    // var order_id=$("#order_id").text;

    var app=new Vue({
        el:"#want_buy",
        data:{
            List:""
        },
        methods:{
            deleteFromShoppingCart:function (goods_id) {
                axios.get("/deleteFromShoppingCart?user_id="+user_id+"&goods_id="+goods_id).then(function (response) {
                    console.log(response.data);
                    if (response.data === true){
                        layer.msg("操作成功!", {icon:1,time:1000},function(){
                            setTimeout('window.location.reload()',10);
                        });
                    }
                },function (err) {
                    console.log(err);
                });
            },
            buy_now:function (order_id) {
                axios.get("/goodsOldOrderWeChat?user_id="+order_id).then(function (response) {
                    console.log(response.data);
                    if(response.data!=null){
                        layui.use('layer', function(){
                            var layer = layui.layer;
                            layer.open({
                                type:2,
                                title:'联系页',
                                content:'/userChat',
                                area: ['300px', '300px'],
                                shade: [0.8, '#393D49'],
                                resize:false,
                                success:function (layero,index) {
                                    var iframe = window['layui-layer-iframe' + index];
                                    iframe.child(response.data)
                                }

                            })
                        });
                    }
                },function (err) {
                    console.log(err.data);
                });
            }
        }
    });

    axios.get("/queryShoppingCart?user_id="+user_id).then(function (response) {
        console.log(response.data);
        app.List=response.data;
    },function (err) {
        console.log(err);
    });
</script>
</html>